home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS04.ADF / idemo / nodos.c < prev    next >
C/C++ Source or Header  |  1985-10-26  |  5KB  |  191 lines

  1. /****************************************************************
  2. *                                                               *
  3. * Copyright 1985, Commodore Amiga Inc.  All rights reserved.    *
  4. * No part of this program may be reproduced, transmitted,       *
  5. * transcribed, stored in retrieval system, or translated into   *
  6. * any language or computer language, in any form or by any      *
  7. * means, electronic, mechanical, magnetic, optical, chemical,   *
  8. * manual or otherwise, without the prior written permission of  *
  9. * Commodore Amiga Incorporated, 983 University Ave, #D          *
  10. * Los Gatos, CA 95030                                           *
  11. *                                                               *
  12. ****************************************************************/
  13.  
  14. /*** nodos.c ***/
  15.  
  16. #include <exec/types.h>
  17. #include <exec/nodes.h>
  18. #include <exec/lists.h>
  19. #include <exec/tasks.h>
  20. #include <exec/memory.h>
  21.  
  22. putc(c)
  23. int c;
  24. {
  25.         KPutChar(c);
  26. }
  27.  
  28. PutChar(c)
  29. int c;
  30. {
  31.         KPutChar(c);
  32. }
  33.  
  34. MayGetChar()
  35. {
  36.         return(KMayGetChar());
  37. }
  38.  
  39. MayGetCh()
  40. {
  41.         return(KMayGetChar());
  42. }
  43.  
  44. printf(a,b,c,d,e,f,g,h,i,j,k)
  45. {
  46.         kprintf(a,b,c,d,e,f,g,h,i,j,k);
  47. }
  48.  
  49. int getmem(a)
  50. int a;
  51. {
  52.         return (AllocMem(a,MEMF_CHIP));
  53. }
  54.  
  55. int GetNum()
  56. {
  57.         int c,n;
  58.         int sign = 1;
  59.         n = 0;
  60.         while ( (c = KGetChar()) != '\r')
  61.         {
  62.                 putc(c);
  63.                 switch(c)
  64.                 {
  65.                         case '-'        :       sign = -sign;
  66.                                                         break;
  67.                         case '\b'       :       n = n/10;
  68.                                                         break;
  69.                         case 'q'        :       exit();
  70.                         default         :       n = n*10 + c - '0';
  71.                 }
  72.         }
  73.         return(sign*n);
  74. }
  75.  
  76. Panic(s)
  77. char *s;
  78. {
  79.         printf("%s\n",s);
  80. }
  81. /*** pio.c ***/
  82. #include "exec/types.h"
  83. #include "exec/nodes.h"
  84. #include "exec/lists.h"
  85. #include "exec/memory.h"
  86. #include "exec/ports.h"
  87. #include "exec/libraries.h"
  88. #include "exec/devices.h"
  89. #include "exec/tasks.h"
  90. #include "exec/io.h"
  91. #include "exec/interrupts.h"
  92. #include "devices/printer.h"
  93.  
  94. union
  95. {
  96.     struct IOStdReq ios;
  97.     struct IODRPReq iodrp;
  98.     struct IOPrtCmdReq iopc;
  99. } printerIO;
  100.  
  101. struct MsgPort replyMsgPort;
  102.  
  103. /* ======================================================================== */
  104. /* ======================================================================== */
  105. /* ======================================================================== */
  106.  
  107. int PrinterOpen(signal) /* open the printer */
  108. int signal;
  109. {
  110.     int error;
  111.         
  112.     /* open the printer device */
  113.     if ((error = OpenDevice("printer.device", 0, &printerIO, 0)) != 0)
  114.         {
  115.         printf("EventInit \"printer.device\" OpenDevice error: %d.\n", error);
  116.         return(error);
  117.         }
  118.  
  119.     printf("printer.device: %lx.\n", printerIO.ios.io_Device);
  120.  
  121.     /* set up the message port in the I/O request */
  122.     replyMsgPort.mp_Node.ln_Type = NT_MSGPORT;
  123.     replyMsgPort.mp_Flags = 0;
  124.     if (signal >= 0)
  125.         {
  126.         printf("Printer signal: %ld\n", signal);
  127.         replyMsgPort.mp_SigBit = signal;
  128.         replyMsgPort.mp_SigTask = (struct Task *) FindTask((char *) NULL);
  129.         }
  130.     else
  131.         {
  132.         printf("Warning.  printer set up for immediate I/O only.\n");
  133.         replyMsgPort.mp_SigBit = 0;
  134.         replyMsgPort.mp_SigTask = 0;
  135.         }
  136.  
  137.     AddPort(&replyMsgPort);
  138.     printerIO.ios.io_Message.mn_ReplyPort = &replyMsgPort;
  139.     return(0);
  140. }
  141.  
  142.  
  143.  
  144. PrinterClose() /* close the printer */
  145. {
  146.     CloseDevice(&printerIO);
  147.     RemPort(&replyMsgPort);
  148. }
  149.  
  150.  
  151.  
  152. /* the dump to printer caller */
  153. VOID PrintRPort(rastPort, colorMap, modes, sx,sy, sw,sh, dc,dr, special)
  154. struct RastPort *rastPort;
  155. UWORD *colorMap;
  156. ULONG modes;
  157. int sx, sy, sw, sh, dc, dr;
  158. UWORD special;
  159. {
  160.     printerIO.iodrp.io_Command = PRD_DUMPRPORT;
  161.     printerIO.iodrp.io_RastPort = rastPort;
  162.     printerIO.iodrp.io_ColorMap = colorMap;
  163.     printerIO.iodrp.io_Modes = modes;
  164.     printerIO.iodrp.io_SrcX = sx;
  165.     printerIO.iodrp.io_SrcY = sy;
  166.     printerIO.iodrp.io_SrcWidth = sw;
  167.     printerIO.iodrp.io_SrcHeight = sh;
  168.     printerIO.iodrp.io_DestCols = dc;
  169.     printerIO.iodrp.io_DestRows = dr;
  170.     printerIO.iodrp.io_Special = special;
  171.     DoIO(&printerIO);
  172. }
  173.  
  174.  
  175.  
  176. VOID pWrite(buffer) /* write to the printer */
  177. char *buffer;
  178. {
  179.     int count;
  180.     char *b;
  181.  
  182.     b = buffer;
  183.     count = 0;
  184.     while (*b++ != '\0') count++;
  185.     /* queue a printer write */
  186.     printerIO.ios.io_Command = CMD_WRITE;
  187.     printerIO.ios.io_Data = buffer;
  188.     printerIO.ios.io_Length = count;
  189.     DoIO(&printerIO);
  190. }
  191.